package cn.tpshion.devops.controller;

import cn.tpshion.devops.common.Result;
import cn.tpshion.devops.domain.vo.FileInfoVO;
import cn.tpshion.devops.service.OSSService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/oss")
public class OSSController {

    @Resource
    private OSSService ossService;

    @PostMapping("/list")
    public Result<List<FileInfoVO>> list(){
        return Result.ok(ossService.list());
    }

    @PostMapping("/download")
    public Result<String> download(@Valid @RequestBody FileInfoVO fileInfo){
        return Result.ok(ossService.download(fileInfo));
    }

    @PostMapping("/delete")
    public Result delete(@Valid @RequestBody FileInfoVO fileInfo){
        ossService.delete(fileInfo);
        return Result.ok();
    }
}
